#ifndef PERMUTATIONS_H 
#define PERMUTATIONS_H

#include <vector>
#include <string>
#include "Permutation.h"
#include "Chain.h"
#include "parsing\chainparser.h"
#include "parsing\inputparmetersparser.h"

using std::string;
using std::vector;

class Permutations
{
public:
	Permutations(VERTEX_SIZE *originalPermutation, int wordLen, int wordWeight, int groupSize, 
				 int maxIntersectionForSave, int minChainLengthForSave, int maxChains, double permutationPercent);
	int GetGroupSize() const; 
	int GetMaxIntersection() const { return m_MaxIntersectionForSave; };
	int GetMaxChains() const { return m_MaxChains; };
	int GetMinChainLength() const { return m_MinChainLengthForSave; };
	void InsertPerm(const Permutation &perm);
	Permutation *GetOriginalPermutation();
	vector<Permutation> GetPermutations() {return m_Permutations;};
	void Fill();
	void CreateAllChains(string chainFileNamePrefix);
	static Permutations *CreatePermutationsObject(ChainParser& chainFile, InputParmetersParser& inputFile);
	void Run();

private:
	int m_WordLen; // How long is each binary word - column count
	int m_WordWeight; // How many bits are on in each binary word
	int m_OriginalGroupSize; // How many words are in the original group
	int m_MaxIntersectionForSave; // The largest intersection with the original group a group can have and still be saved
	int m_MinChainLengthForSave; // The minimal chain length for a chain to be saved
	int m_MaxChains; // The maximal number of chains to save
	double m_PermutationPercent; // the percent of permutations to calculate from the (m_WordLen!) possibilities.
	vector<Permutation> m_Permutations;
	vector<Chain> m_Chains;
	string m_ChainFileNamePrefix; 
	
	int CreateChains(Permutation *perm, Chain chain, int chainCount);
	void AddPermutationToList(Permutation *perm, int intersectionWithOriginal);
	string GetCurrentTimeStamp();
	unsigned long long CalcFactorial(int base);
};

#endif
